import request from '@/utils/request';

// 获取制度
export function fetchInstitutions(params) {
    return request('/api/oa/v1/institutions/origin', {
        method: 'GET',
        params
    });
}

// 获取考勤设置列表
export function fetchAttendance(params) {
    return request('/api/oa/v1/attendance/group', {
        method: 'GET',
        params
    });
}

// 获取考勤设置列表（分页）
export function getAttendanceList(params) {
    return request('/api/oa/v1/attendance/group', {
        method: 'POST',
        data: params
    });
}

// 获取考勤设置详情
export function fetchAttendanceById(id) {
    return request(`/api/work/v1/attendance/groups/${id}`, {
        method: 'GET'
    });
}

// 更新考勤设置
export function updateAttendance(data) {
    return request('/api/work/v1/attendance/groups/setting', {
        method: 'POST',
        data
    });
}

// 列表-删除考勤设置
export function delateAttendance(id) {
    return request(`/api/work/v1/attendance/groups/deleteded/${id}`, {
        method: 'DELETE'
    });
}

/**
 *获取公司人员列表
 *
 * @export POST
 * @param {integer} companyId 公司id
 * @returns
 */
export async function getEmployeeList(companyId) {
    return new Promise(async (resolve, reject) => {
        const res = await request('/api/org/v1/employeeInfo/simpleInfo/list', {
            method: 'POST',
            data: {
                getChildByOrganizationCode: companyId,
                pageSize: 1000000,
                serviceStatus: [1, 2, 4, 5]
            }
        });
        const { code, data } = res;
        if (code === 10000) {
            const finalData = {
                ...res,
                data: data.filter(
                    item => item.employeeCode !== 'oa1135823925744009218' || item.employeeName !== 'admin'
                )
            };
            resolve(finalData);
        } else {
            reject(res);
        }
    });
}
